package com.djl.rabbitmq.seven;

import com.djl.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rabbitmq.client.Delivery;

/**
 * @program: rabbitmq-hello
 * @description: 声明主题交换机及相关队列
 * @author: Mr.dai
 * @create: 2021-09-12 17:00
 **/

public class ReceiveLogTopic01 {
    public static  final  String EXCHANGE_NAME ="topic_logs";

    public static void main(String[] args) throws Exception {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //绑定交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC);
        //声明一个队列
        String queueName="q1";
        channel.queueDeclare(queueName,false,false,false,null)  ;
        channel.queueBind(queueName,EXCHANGE_NAME,"*.orange.*");
        System.out.println("等待接收消息。。。。");
        //接收消息 使用信道接收消息
        DeliverCallback deliverCallback=( consumerTag, message)->{
            System.out.println(new String(message.getBody(),"Utf-8"));
            System.out.println("接收队列："+queueName+"绑定键："+message.getEnvelope().getRoutingKey());
        };
        channel.basicConsume(queueName,true,deliverCallback,consumerTag -> {});

    }
}
